<?php
/**
 * Created by PhpStorm.
 * User: echo
 * Date: 2017/12/7
 * Time: 19:59
 */

namespace App\Http\Controllers\Common;


use App\Http\Controllers\Controller;

class WriteConfigController extends Controller
{
    #写入配置信息
    public function writeConfig($arr, $path)
    {
        ob_start();
        var_export($arr);
        $arrStr = ob_get_contents();
        ob_end_clean();
        $config = '<?php' . PHP_EOL
            . 'return ' . $arrStr . ';';
        if (file_exists($path)) {
            unlink($path);
        }
        $res = file_put_contents($path, $config);
        if ($res) {
            return 'ok';
        } else {
            return 'faild';
        }
    }
}